﻿using System.Windows;
using System.Windows.Controls;
using System.ServiceModel.DomainServices.Client.ApplicationServices;

namespace DYSales
{
    public partial class App : Application
    {
        private BusyIndicator progressIndicator;
        public App()
        {
            this.Startup += this.Application_Startup;
            this.UnhandledException += this.Application_UnhandledException;

            InitializeComponent();

            WebContext webContext = new WebContext();
            webContext.Authentication = new FormsAuthentication();
            this.ApplicationLifetimeObjects.Add(webContext);
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.progressIndicator = new BusyIndicator();
            this.Resources.Add("MainProgress", this.progressIndicator);
            this.progressIndicator.Style = Resources["BusyIndicatorRoundedStyle"] as Style;
            this.progressIndicator.HorizontalAlignment = HorizontalAlignment.Stretch;
            this.progressIndicator.VerticalAlignment = VerticalAlignment.Stretch;

            //Replace new MainPage() with the name of your starting xaml page;
            this.progressIndicator.Content = new MainPage();

            this.RootVisual = this.progressIndicator;
            //this.RootVisual = new MainPage();
        }

        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            // If the app is running outside of the debugger then report the exception using
            // a ChildWindow control.
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                // NOTE: This will allow the application to continue running after an exception has been thrown
                // but not handled. 
                // For production applications this error handling should be replaced with something that will 
                // report the error to the website and stop the application.
                //e.Handled = true;
                //ChildWindow errorWin = new ErrorWindow(e.ExceptionObject);
                //errorWin.Show();
            }
        }
    }
}